package com.xwj.config;

import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.BlockRequestHandler;
import com.alibaba.fastjson.JSON;
import com.xwj.dto.CommonResult;
import org.springframework.http.HttpStatus;
import org.springframework.web.reactive.function.server.ServerResponse;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * nacos-order-consumer服务自定义逻辑处理被限流的请求
 * @author wjxu17
 * @date 2022/3/23 14:17
 */
public class ConsumerOrderBlockRequestHandler implements BlockRequestHandler {
    @Override
    public Mono<ServerResponse> handleRequest(ServerWebExchange exchange, Throwable t) {
        return ServerResponse.status(HttpStatus.TOO_MANY_REQUESTS).bodyValue(JSON.toJSONString(CommonResult.error("接口被限流")));
    }
}
